package com.jiazhong.springmvc.test01;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Objects;

/**
 * @Auther:shuXin
 */
@Controller
@RequestMapping("param")
public class MvcController {
    /**
     * 直接传参数的方法
     *
     * @param name
     * @param age
     * @return
     */
    @RequestMapping(value = "value")
    @ResponseBody
    public String getInfo(String name, Integer age) {
        System.out.println(name + " " + age);
        return name + " " + age;
    }

    /**
     * @param name
     * @param age
     * @return
     * @RequestParam来进行传值 value = "account" 起了一个名字，然后必须按照起的这个名字进行赋值
     * required = false 表示这个参数是可选的
     * defaultValue = "20" 默认值
     */
    @GetMapping("info")
    @ResponseBody
    public String getValue(@RequestParam(value = "account") String name,
                           @RequestParam(required = false, defaultValue = "20") Integer age) {
        System.out.println(name + " " + age);
        return name + " " + age;
    }

    /**
     * 一名多值
     *
     * @param hbs
     * @return
     */
    @RequestMapping("values")
    @ResponseBody
    public String getValues(@RequestParam List<Object> hbs) {
        System.out.println(hbs);
        return "ok";
    }

    /**
     * 获取实体类的对象的数据传递
     * postman接口测试工具
     * @param user
     * @return
     */
    @RequestMapping("user")
    @ResponseBody
    public String getUser(User user) {
        System.out.println(user);
        return "ok";
    }
}
